package com.example.treehole;

import android.view.View;

import com.example.treehole.base.BaseBindingActivity;
import com.example.treehole.databinding.ActivityRegisterBinding;
import com.example.treehole.util.Api;
import com.example.treehole.util.HttpUtil;

import java.util.HashMap;

public class RegisterActivity extends BaseBindingActivity<ActivityRegisterBinding> {


    @Override
    protected void initListener() {

    }



    @Override
    protected void initData() {

        viewBinder.tvRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String phone = viewBinder.etPhone.getText().toString();
                String email = viewBinder.etEmail.getText().toString();
                String password = viewBinder.etPassword.getText().toString();
                String nickname = viewBinder.etNickname.getText().toString();
                if (phone.isEmpty()) {
                    toast("请输入登录手机号");
                    return;
                }
                if (password.isEmpty()) {
                    toast("请输入密码");
                    return;
                }
                if (email.isEmpty()) {
                    toast("请输入邮箱");
                    return;
                }
                if (nickname.isEmpty()) {
                    toast("请输入昵称");
                    return;
                }
                showLoading();
                HashMap<String, Object> params = new HashMap<>();
                params.put("nickname", nickname);
                params.put("password", password);
                params.put("email", email);
                params.put("face", "https://img0.baidu.com/it/u=4196418831,3741244744&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500");
                params.put("phone", phone);
                params.put("type", "用户");
                HttpUtil.post(Api.REGISTER, params, new HttpUtil.OnNetStringListener() {
                    @Override
                    public void success(String data, String message) {
                        dismissLoading();
                        toast(message);
                        finish();
                    }

                    @Override
                    public void error(String error) {
                        dismissLoading();
                        toast(error);
                    }
                });

            }
        });
    }


}